<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/mcStyle.css"/>
        <link rel="stylesheet" type="text/css" href="css/print.css" media="print">
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript">
          google.load("visualization", "1", {packages:["corechart"]});
          google.setOnLoadCallback(drawChart);
          function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Food Type');
            data.addColumn('number', 'Times Selected');
       		
                    <?php
                            include('session.php');
                            require_once('database.php');

                            $startDate = $_POST['startDate'];
                            $endDate = $_POST['endDate'];

                            //Grab results from database
                            $results = $database->getLogCount($startDate,$endDate);

                            // Prints out the javascript for Google Chart API
                            echo 'data.addRows(5);';
                            $counter = 0;
                            $colors = "";
                            while($row = mysql_fetch_array($results)) {
                                    echo "data.setValue(".$counter.", 0, '".$row['description']."');";
                                    echo "data.setValue(".$counter.", 1, ".$row['total'].");";
                                    $colors .= "'".$row['name']."', ";
                                    $counter++;
                            }

				echo "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
            			chart.draw(data,{width: 770, 
                                                height: 400, 
                                                colors:[".$colors."],
                                                titleTextStyle:{fontName:'calibri',
                                                                fontSize:'24'  
                                                                }, 
                                                fontSize:'16', 
                                                backgroundColor: '#ffffff',
                                                titleTextStyle:{color:'black',
                                                                fontName:'calibri',
                                                                fontSize:'24'
                                                                },
                                                tooltipTextStyle:{color:'black',
                                                                fontName:'calibri',
                                                                fontSize:'16'
                                                                },
                                                tooltipText:'value',
                                                title: 'Sales breakdown from ".$startDate." to ".$endDate."'

                                                });"
			?>
          }//end function drawChart
        </script>
        <title>McCanada Restaurants</title>
    </head>
    <body>
        <?php
        include('header.php');
        ?>
        
                <div id="chart_div">No Orders Found For The Dates Entered</div>
                
                <!-- display next days food special -->
                <div class="special">
                    <?php
 			   //This database function returns the next days special(s)
                           $results = $database->getSpecial($startDate,$endDate);
                           
                           if($results !== NULL){
                               $string1 = "";
                               while($row = mysql_fetch_array($results)) {
                                   $string1 .= $row['name'];
                                   $string1 .= ', ';
                               }

                               $string2 = substr($string1,0,-2); // make the string look presentable
                           
                               //our final result of the next days special is printed to the screen
                               echo 'Recommended special(s) for the next day is: '.'<br />'.$string2;
                           }
                    
                    ?>
                </div>

        <?php
        include('footer.php');
        ?>
    </body>
</html>


